import React from 'react'
import { changeNav,getServiceinfo } from '../actions'
import { connect } from 'react-redux'
import { Button,List,Badge,WhiteSpace } from 'antd-mobile'
import BizopenApply from '../components/BizopenApply.js'
import hhistory from '../history'
import CSSModules from 'react-css-modules'
import styles from './tenant.less'
import { syAjaxGet } from '../common/ajaxservice.js'
import {ajaxGet} from "../common/jsajaxservice";

const Item = List.Item;
const Brief = Item.Brief;
@CSSModules(styles, { allowMultiple: false })

class Mine extends React.Component{
	componentWillMount(){
		this.props.getServiceinfo( this.props.loginStatus.user.servicerCode )
	}
	
	componentDidMount(){
		this.props.tochangeNav({title:"我的",rbtn:[
			<Button key="1" type="primary" inline size="small"
				onClick={ ()=>{ hhistory.push('/setPage') } }
			>设置</Button>
		]});
        syAjaxGet('auth/login').then( (res) => {
            console.log(res, '111111111')
            this.servicerphoto = res.data.user.photo
            this.fullname = res.data.user.fullname
            this.email = res.data.user.email
            this.orgname = res.data.role.roleName
        })
	}

	render(){
		const { servicerInfo } = this.props
		return(
			<div className='mine'>
				<WhiteSpace size="lg" />
				<List className="my-list">
			    	<Item arrow="horizontal" 
			        	  onClick = { ()=>{ hhistory.push("/myAccount") } }
			        	  multipleLine>
						<img style={{ width:"0.9rem",height:"0.9rem" ,float:'left',marginTop:'0.15rem',marginRight:'0.2rem'}} src={ this.servicerphoto } />
						<Brief>
							<p style={{fontSize:'0.3rem',color:"#333"}}>	{ this.fullname }</p>
							<p>	{ this.email }</p>
						</Brief>
			        </Item>
			        <Item arrow="horizontal"
						onClick = { ()=>{ hhistory.push("/companyInfo") } }>
						{ this.orgname }
			        </Item>
			    </List>
			    <WhiteSpace size="lg" />
			    <BizopenApply></BizopenApply>
			    <WhiteSpace size="lg" />
			    <List className="my-list">
			        <Item arrow="horizontal"
			        onClick = { ()=>{ hhistory.push("/stuffManage") } }>
			          员工管理
			        </Item>
			        
			    </List>
			</div>
		)
	}
}

const mapStateToProps = ( state ) => ({
		loginStatus:state.loginStatus,
		servicerInfo:state.servicerInfo
})

const mapDispatchToProps = ( dispatch ) => {
	return{
		tochangeNav:navobj => dispatch( changeNav( navobj ) ),
		getServiceinfo:code => dispatch( getServiceinfo( code ) )
	}
}

export default connect(mapStateToProps,mapDispatchToProps)(Mine)